package com.service.impl;

import java.util.List;

import com.dao.CustomerDAO;
import com.dao.impl.CustomerDAOImpl;
import com.model.Customer;
import com.service.CustomerService;
import com.util.jsonUtil;

public class CustomerServiceImpl implements CustomerService {
	private CustomerDAO customerDAO = new CustomerDAOImpl();

	@Override
	public boolean addCustomer(Customer customer) {
		return customerDAO.addCustomer(customer);
	}

	@Override
	public boolean deleteCustomer(int id) {
		return customerDAO.deleteCustomer(id);
	}

	@Override
	public boolean updateCustomer(Customer customer, int id) {
		return customerDAO.updateCustomer(customer, id);
	}

	@Override
	public String selectCustomer(String key, String type, int page, int rows,
			String sort, String order) {
		List<?> list = customerDAO.selectCustomer(key, type, page, rows, sort,
				order);
		int total;
		if (key != null) {
			total = customerDAO.getLikeTotal(key, type);
			return jsonUtil.toJson(list, total);
		} else {
			total = customerDAO.getTotal();
			return jsonUtil.toJson(list, total);
		}

	}
}
